package com.linewell.license.demo.service;

import com.linewell.license.demo.bean.UserDetail;
import com.linewell.license.demo.dao.UserDao;
import com.linewell.license.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author
 * Company:
 * Createtime : 2019/10/21 14:39
 * Description :
 */
@Service
public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        User user = userDao.getUserByUserName(userName);
        if(user == null){
            return null;
        }
        UserDetail detail = new UserDetail();
        detail.setPassword(user.getPassword());
        detail.setUsername(user.getUserName());
        detail.setUser(user);
        return detail;
    }
}
